import com.troyworks.framework.ui.BaseComponent;
import com.troyworks.events.TProxy;

/**
 * @author Troy Gardner
 */
class com.troyworks.framework.ui.MCLoadingProgressIndicator extends BaseComponent {

	private var error_mc : MovieClip;

	private var percent_loaded_mc : MovieClip;

	private var percent_total_mc : MovieClip;
	
	function MCLoadingProgressIndicator(clip : MovieClip) {
		super(null, "MCLoadingProgressIndicator");
				trace("new MCLoadingProgressIndicator " + clip + " " + this);
	}
	public function onLoad():Void{
		trace("MCLoadingProgressIndicator.onLoad" + this + " " + this.gotoLoadingPercent);
		error_mc._visible = false;
		percent_loaded_mc._visible = false;
		percent_loaded_mc._width =1;
		stop();
	}
	public function gotoLoadingPercent(p:Number):Void{
			trace("MCLoadingProgressIndicator.gotoLoadingPercent" + p + " " + percent_loaded_mc._width);
		if(p == -1){
			error_mc._visible = true;
		}else if(p>= 100){
	//		gotoAndPlay("loadingComplete");
			onEnterFrame = TProxy.create(this, onEnterFrameHandler);
		}else{
			percent_loaded_mc._visible = true;
			percent_total_mc._visible = true;
			percent_loaded_mc._width = p;
		}
	}
	public function onEnterFrameHandler() : Void {
		this._alpha -= 2;
		if(this._alpha <= 0){
			delete onEnterFrame;
		}
	}
}